﻿//	Ordinaire.Security.Model.UserRole
//	Copyright (c) 2011 Jonathan Loe
//
//	MIT license (http://en.wikipedia.org/wiki/MIT_License)
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights 
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
//	of the Software, and to permit persons to whom the Software is furnished to do so, 
//	subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in all 
//	copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//	INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
//	PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//	FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;

using Ordinaire.Data;

namespace Ordinaire.Security.Data
{
    /// <summary>
    /// Class representation of table 'UserRoles'.
    /// </summary>
    [Table]
    public class UserRoles : Data<int, string>
    {
        #region Variables

        /// <summary>
        /// User id
        /// </summary>
        protected int userId;

        /// <summary>
        /// Role id
        /// </summary>
        protected int roleId;

        /// <summary>
        /// Storage for relationship "FK_UserRoles_Users"
        /// </summary>
        private EntityRef<Users> users = new EntityRef<Users>();

        /// <summary>
        /// Storage for relationship "FK_UserRoles_Roles"
        /// </summary>
        private EntityRef<Roles> roles = new EntityRef<Roles>();

        #endregion

        #region Properties

        #region Column

        /// <summary>
        /// Get or set unique id
        /// </summary>
        [Column(DbType = "int IDENTITY NOT NULL", IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
        public override int Id
        {
            get { return base.Id; }
            set { base.Id = value; }
        }

        /// <summary>
        /// Get or set user id
        /// </summary>
        [Column(IsPrimaryKey = true, UpdateCheck=UpdateCheck.Never)]
        public int UserId
        {
            get { return this.userId; }
            set { this.userId = value; }
        }

        /// <summary>
        /// Get or set role id
        /// </summary>
        [Column(IsPrimaryKey = true, UpdateCheck = UpdateCheck.Never)]
        public int RoleId
        {
            get { return this.roleId; }
            set { this.roleId = value; }
        }

        /// <summary>
        /// Get or set creator
        /// </summary>
        [Column(DbType = "nvarchar(10) NOT NULL", UpdateCheck=UpdateCheck.Never)]
        public override string CreatedBy
        {
            get { return base.CreatedBy; }
            set { base.CreatedBy = value; }
        }

        /// <summary>
        /// Get or set creation date
        /// </summary>
        [Column(UpdateCheck=UpdateCheck.Never)]
        public override Nullable<DateTime> CreateDate
        {
            get { return base.CreateDate; }
            set { base.CreateDate = value; }
        }

        /// <summary>
        /// Get or set updator
        /// </summary>
        [Column(DbType = "nvarchar(10)", UpdateCheck=UpdateCheck.Never)]
        public override string UpdatedBy
        {
            get { return base.UpdatedBy; }
            set { base.UpdatedBy = value; }
        }

        /// <summary>
        /// Get or set update date
        /// </summary>
        [Column(UpdateCheck=UpdateCheck.Never)]
        public override Nullable<DateTime> UpdateDate
        {
            get { return base.UpdateDate; }
            set { base.UpdateDate = value; }
        }

        #endregion

        #region Association

        /// <summary>
        /// Gets or sets the associated role.
        /// </summary>
        [Association(Name = "FK_UserRoles_Roles", IsForeignKey = true, Storage = "roles", ThisKey = "RoleId")]
        public Roles Role
        {
            get { return roles.Entity; }
            set { roles.Entity = value; }
        }

        /// <summary>
        /// Gets or sets the associated user.
        /// </summary>
        [Association(Name = "FK_UserRoles_Users", IsForeignKey = true, Storage = "users", ThisKey = "UserId")]
        public Users User
        {
            get { return users.Entity; }
            set { users.Entity = value; }
        }

        #endregion

        #endregion
    }
}
